package jeme.lang;

import java.util.ArrayList;

import jeme.math.SchemeInteger;

/**
 *
 *
 * @author Erik Silkensen (silkense@colorado.edu)
 * @version Mar 19, 2009
 */
public class SchemeVector extends SchemeObject
{
    private ArrayList<SchemeObject> elements;
    
    /**
     * 
     */
    public SchemeVector()
    {
        elements = new ArrayList<SchemeObject>();
    }
    
    /**
     * 
     * @param elements
     */
    public SchemeVector(SchemeObject[] elements) 
    {
        this.elements = new ArrayList<SchemeObject>();
        this.elements.ensureCapacity(elements.length);
        for (SchemeObject el : elements) {
            this.elements.add(el);
        }
    }
    
    /**
     * 
     * @return
     */
    public SchemeInteger length()
    {
        return new SchemeInteger(Integer.toString(elements.size()), 10);
    }
    
    /**
     * 
     * @param index
     * @return
     */
    public SchemeObject get(int index)
    {
        return elements.get(index);
    }
    
    /**
     * 
     * @param index
     * @param element
     * @return
     */
    public SchemeObject set(int index, SchemeObject element)
    {
        return elements.set(index, element);
    }
    
    /*
     * (non-Javadoc)
     * @see jeme.lang.SchemeObject#toString()
     */
    public String toString()
    {
        String ext = "#(";
        
        for (int i = 0; i < elements.size(); i++) {
            ext += elements.get(i) + (i == elements.size() - 1 ? "" : " ");
        }
        
        return ext + ")";
    }
}
